<?php
class hrd_jadwal_model extends MY_Model {
	var $nama_tabel = 'hrd_jadwal';
	
	function GetJSON() {
		$ls_sql	= "	SELECT	a.*, b.nama_periode, c.nama_grub_absen, b.tgl_mulai, b.tgl_selesai
					FROM	".$this->nama_tabel." a
					LEFT JOIN hrd_periode b ON a.id_periode_fk = b.id_periode_pk
					LEFT JOIN hrd_grub_absen c ON a.id_grub_absen_fk = c.id_grub_absen_pk
					WHERE	(UPPER(id_jadwal_pk) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(b.nama_periode) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(c.nama_grub_absen) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(NVL(ket_jadwal,'')) LIKE '%".strtoupper(post('keyword'))."%')
					AND id_periode_fk like '%".post('id_periode_cari')."%'
					ORDER BY ".(post('sort')=='' ? 'a.tgl_rekam' : post('sort'))." ".(post('order')=='' ? 'desc' : post('order'));
					
					
		return json_encode( $this->paging($ls_sql) );
	}

	function Add($arr_data){
		$this->db->insert($this->nama_tabel, $arr_data);
	}

	function Update($arr_data, $arr_rule){
		$this->db->update($this->nama_tabel, $arr_data, $arr_rule);
	}

	function DeleteSingle($arr_rule) {
		try {
			$this->db->delete($this->nama_tabel, array('id_jadwal_pk' => $arr_rule['id_jadwal_pk']));
			return '';
		} catch(Exception $e) {
			return $e->getMessage();
		}
	}

	function GetSingleView($id_jadwal_pk) {
		$sql = "select a.*
				from hrd_jadwal a
				where a.id_jadwal_pk = '".strtoupper($id_jadwal_pk)."'
				";

		$result = $this->db->query($sql);


		if($result->num_rows() == 1) {
			return $result->row_array();
		} else {
			return NULL;
		}

	}

}
?>